﻿using System.Xml;
using LocalTest.Web.Consts;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;

namespace LocalTest.Web.Middleware;

public class RedisTokenHandler : JsonWebTokenHandler
{
    public override async Task<TokenValidationResult> ValidateTokenAsync(SecurityToken token,
        TokenValidationParameters validationParameters)
    {
        var webToken = token as JsonWebToken;
        if (webToken is null)
        {
            return new TokenValidationResult()
                { IsValid = false, Exception = new FormatException(Messages.TokenFormatValid) };
        }

        webToken.Claims.FirstOrDefault(c => c.Type == SystemToken.UIdToken);
        var result = await base.ValidateTokenAsync(token, validationParameters);
        return result;
    }
}